import torch
import common


def text2Vec(text):
    # 4列36行  4列是4个验证码，36行是验证码词库的长度10+26个英文字母
    vev = torch.zeros(common.captcha_size, len(common.captcha_array))
    for i in range(len(text)):
        vev[i, common.captcha_array.index(text[i])] = 1
    return vev


def vec2Text(vec):
    vec = torch.argmax(vec, dim=1)
    text=""
    for i in vec:
        text+=common.captcha_array[i]
    return text

if __name__ == '__main__':
    vec = text2Vec("aab1")
    print(vec, vec.shape)
    print(vec2Text(vec))
